<template>
	<view class="page">
		<u-navbar bgColor="rgba(255,255,255,0)" :auto-back="true">
			<!-- uview没有接口可以修改title的颜色 -->
			<view class="u-nav-slot" slot="center">
				<text style="color: #000">签到</text>
			</view>
		</u-navbar>
		<view class="page-top">
			<image class="bg" src="/static/images/signin.png" mode="widthFix"></image>
			<view class="top-texts">
				<view class="lable">我的能量值</view>
				<view class="value">{{ detail.power || 0 }}</view>
				<view class="title">已连续签到 {{ detail.sign_in_days || 0 }} 天</view>
			</view>
		</view>
		<view class="page-main">
			<view class="title">每日任务</view>
			<view class="item">
				<view class="left">
					<view class="iconView">
						<image class="icon" src="/static/images/形状 2.png" mode="widthFix"></image>
					</view>
					<view class="left-text">
						<view class="left-title">每日签到</view>
						<view class="left-subtitle">可获得 1 能量值</view>
					</view>
				</view>
				<view v-if="detail.sign_in_today == 0" class="right" @click="signIn">签到</view>
				<view v-else class="right active">已签到</view>
			</view>
			<view class="tip">连续签到5天可获得 10能量</view>
			<view class="item">
				<view class="left">
					<view class="iconView">
						<image class="icon" src="/static/images/shipin 2.png" mode="widthFix"></image>
					</view>
					<view class="left-text">
						<view class="left-title">观看1个视频</view>
						<view class="left-subtitle">可获得 1 能量值</view>
					</view>
				</view>
				<view class="right">去看看</view>
			</view>
			<view class="item">
				<view class="left">
					<view class="iconView">
						<image class="icon" src="/static/images/shipin 2.png" mode="widthFix"></image>
					</view>
					<view class="left-text">
						<view class="left-title">观看3个视频</view>
						<view class="left-subtitle">可获得 5 能量值</view>
					</view>
				</view>
				<view class="right">去看看</view>
			</view>
			<view class="item">
				<view class="left">
					<view class="iconView">
						<image class="icon" src="/static/images/shipin 2.png" mode="widthFix"></image>
					</view>
					<view class="left-text">
						<view class="left-title">观看10个视频</view>
						<view class="left-subtitle">可获得 20 能量值</view>
					</view>
				</view>
				<view class="right">去看看</view>
			</view>
		</view>
	</view>
</template>

<script>
import httpApi from '../../../http';
export default {
	data() {
		return {
			detail: {
				power: 0, //能量值
				sign_in_days: 0, //连续签到天数
				sign_in_today: 0 //今天是否签到
			}
		};
	},
	onLoad() {
		this.init();
	},
	methods: {
		init() {
			httpApi.MyApi.signInCenter({}).then((res) => {
				this.detail = res.data;
			});
		},
		signIn() {
			if (this.detail.sign_in_today == 0) {
				httpApi.MyApi.signIn({}).then((res) => {
					this.init();
				});
			} else {
				uni.showToast({
					title: '今天已签到',
					icon: 'none'
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
$btn-bg: #cfae7d;
.page {
	background: #fafafa;
}
.page-top {
	width: 750rpx;
	height: 528rpx;
	position: relative;
	.bg {
		width: 750rpx;
		z-index: -1;
	}
	.top-texts {
		position: absolute;
		top: 186rpx;
		left: 48rpx;
		z-index: 1;
		.lable {
			font-family: SourceHanSerifCN, SourceHanSerifCN;
			font-weight: 400;
			font-size: 28rpx;
			color: #2e2e2e;
			line-height: 40rpx;
		}
		.value {
			font-family: SourceHanSerifCN, SourceHanSerifCN;
			font-weight: bold;
			font-size: 76rpx;
			color: #2e2e2e;
			line-height: 76rpx;
			margin-top: 10rpx;
		}
		.title {
			font-family: SourceHanSerifCN, SourceHanSerifCN;
			font-weight: 500;
			font-size: 32rpx;
			color: #26323f;
			line-height: 46rpx;
			margin-top: 32rpx;
		}
	}
}
.page-main {
	width: 690rpx;
	background: #ffffff;
	border-radius: 20rpx;
	padding: 30rpx;
	box-sizing: border-box;
	position: relative;
	top: -80rpx;
	left: 50%;
	transform: translate(-50%);
	.title {
		font-family: SourceHanSerifCN, SourceHanSerifCN;
		font-weight: 500;
		font-size: 30rpx;
		color: #333333;
		line-height: 42rpx;
		margin-top: 10rpx;
		margin-bottom: 20rpx;
	}
	.item {
		margin: 40rpx 0 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.left {
			display: flex;
			align-items: center;
			.iconView {
				width: 84rpx;
				height: 84rpx;
				border-radius: 50%;
				background-color: #fdf8ee;
				display: flex;
				justify-content: center;
				align-items: center;
				.icon {
					width: 38rpx;
				}
			}
			.left-text {
				display: flex;
				flex-direction: column;
				justify-content: center;
				margin-left: 20rpx;
				.left-title {
					font-family: SourceHanSerifCN, SourceHanSerifCN;
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
					line-height: 40rpx;
				}
				.left-subtitle {
					font-family: SourceHanSerifCN, SourceHanSerifCN;
					font-weight: 400;
					font-size: 22rpx;
					color: #a7a7a7;
					line-height: 32rpx;
				}
			}
		}

		.right {
			width: 140rpx;
			height: 56rpx;
			border-radius: 10rpx;
			font-family: SourceHanSerifCN, SourceHanSerifCN;
			font-weight: 500;
			font-size: 28rpx;
			color: #ffffff;
			line-height: 56rpx;
			text-align: center;
			background-color: $btn-bg;
		}
		.active {
			background-color: #eee;
			color: #999;
		}
	}
	.tip {
		margin-top: 20rpx;
		padding-left: 18rpx;
		box-sizing: border-box;
		width: 394rpx;
		height: 48rpx;
		background: linear-gradient(83deg, #cfae7d 0%, rgba(207, 174, 125, 0) 100%);
		border-radius: 24rpx;
		// opacity: 0.4;
		font-family: SourceHanSerifCN, SourceHanSerifCN;
		font-weight: 400;
		font-size: 22rpx;
		color: #3e2e17;
		line-height: 48rpx;
	}
}
</style>
